'use strict';

const Controller = require('egg').Controller;
const qiniu = require('qiniu')

class QnToken extends Controller {
  async qnToken() {
    const {
      ctx
    } = this;
    let accessKey = 'IPjyn4ydN8QxlXoKyJ8oNY2icvLOw6rBZaBUZp3C';
    let secretKey = 'mEkIkvOaiHpc_FSHxuiiJF1_wBZCibcgfObzkU56';
    let mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
    let options = {
      scope: 'wxhzzzz',
      expires: 36000
    };
    let putPolicy = new qiniu.rs.PutPolicy(options);
    let uploadToken = putPolicy.uploadToken(mac);
    ctx.body = {
      code: 200,
      data: {
        token: uploadToken
      }
    }
  }
}

module.exports = QnToken;